package app.common.utils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 编号发电机
 * @author feizns
 * @since 2023/07/18
 */
public class IdGenerator {

    /**
     * 编号发电机
     */
    private final Map<String, Long> idGenerator = new ConcurrentHashMap<>();

    /**
     * 下一个
     * @param key 关键
     * @return {@link Long}
     */
    public Long next(String key) {
        Long nextId = idGenerator.getOrDefault(key, 0L);
        idGenerator.put(key, nextId + 1);
        return nextId;
    }

}
